package org.xiaom.butler.dbService;

import java.util.List;

import org.xiaom.butler.util.DBHelper;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public abstract class BeanDataService<T> {
	protected SQLiteDatabase db;
	protected DBHelper dbHelper;
	protected Context context;

	public BeanDataService(Context context) {
		this.context = context;
		dbHelper = new DBHelper(context);
		db = dbHelper.getWritableDatabase();
	}

	abstract public void insert(List<T> beans);

	abstract public void update(List<T> beans);

	abstract public void delete(String[] ids);

	abstract public List<T> get(String[] ids);

	abstract public void deleteAll();

	abstract T parseBean(Cursor c);

	abstract ContentValues splitBean(T bean);

	@Override
	protected void finalize() throws Throwable {
		this.db.close();
		this.db = null;
		super.finalize();
	}
}
